﻿/*************************************************
作者: Plane
邮箱: 1785275942@qq.com
功能: 账号登录业务系统

           ~~获取更多教学资讯~~
//----------------*----------------\\
        教学官网：www.qiqiker.com
        官方微信服务号: qiqikertuts
        Plane老师微信: PlaneZhong
\\----------------*----------------//
*************************************************/

using PEProtocol;
using UnityEngine;
using System.Collections.Generic;

public class AcctSys : ILogic {
    //-------------Declaration----------------//
    PERoot root; NetSvc netSvc; EvtSvc evtSvc; UISvc uiSvc;
    List<RoleData> roleDatas;
    public List<RoleData> RoleDatas {
        get => roleDatas;
        set {
            roleDatas = value;
            evtSvc.SendEvt(EvtID.OnRoleDataUpdated, roleDatas);
        }
    }
    public string account;

    //-------------Flow Functions-------------//
    public void Init() {
        root = PERoot.Instance;
        netSvc = root.netSvc;
        evtSvc = root.evtSvc;
        uiSvc = root.uiSvc;
        System.Random rd = new();
        account = $"plane_ {rd.Next(1000, 9999)}";

        this.Log("Init AcctSys Done.");
    }
    public void Tick() {
        //Note:模拟跳转关卡通知下达
        if (Input.GetKeyDown(KeyCode.Alpha3)) {
            NtfRoleDatas(new NetMsg {
                ntfRoleDatas = new() {
                    roleDatas = new() {
                        new(){ uid = 1001,nickName="plane1001",level= 6,exp =100},
                        new(){ uid = 1002,nickName="plane1002",level= 66,exp =200},
                        new(){ uid = 1003,nickName="plane1003",level= 666,exp =300},
                    }
                }
            });
        }
    }
    public void UnInit() {
        this.Log("UnInit AcctSys.");
    }

    //-------------Core Functions-------------//
    void NtfRoleDatas(NetMsg msg) {
        if (msg.errorCode == ErrorCode.None) {
            RoleDatas = msg.ntfRoleDatas.roleDatas;
        }
        else {
            this.Error($"Error:{msg.errorCode}");
        }
    }
}